from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .api import workflows, upload, execute, ml_models
from .api.v1.api import api_router as api_v1_router
from .core.config import settings
from .init_db import init_db

app = FastAPI(title="ML Workflow")

# Set all CORS enabled origins
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(api_v1_router, prefix=settings.API_V1_STR)
app.include_router(workflows.router, prefix="/api")
app.include_router(upload.router, prefix="/api")
app.include_router(execute.router, prefix="/api")
app.include_router(ml_models.router, prefix="/api/ml")

@app.on_event("startup")
async def startup_event():
    init_db()

@app.get("/")
def root():
    return {"message": "Hello World"} 